package com.sphd.emanu.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.emanu.R;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.pojo.goods.Commodity;
import com.sphd.emanu.pojo.goods.Image;
import com.squareup.picasso.Picasso;
import com.wzutils.BigDisMailUtils;
import com.wzutils.L;

import java.util.List;

/**
 * @Author Hu
 * @Time 2017/4/28 --16:48.
 * @Email 87683202@qq.com
 */
public class GoodslistAdapter extends BaseQuickAdapter<Commodity, BaseViewHolder> {
    Context context;

    public GoodslistAdapter(int layoutResId, List<Commodity> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, Commodity item) {
        Image imagesEntity = item.getImages();
        helper
                .setText(R.id.good_name, item.getName())
                .setText(R.id.good_price, "￥" + BigDisMailUtils.turnTrim(item.getUnitPrice(), Constant.POINT))
                .setText(R.id.good_type,item.getShelved()?"上架" : "下架")
                .setTextColor(R.id.good_type,
                        ContextCompat.getColor(context,item.getShelved()? R.color.colorPrimary : R.color.red))
                .addOnClickListener(R.id.look_over_goods_from);
            Picasso.with(context).load(imagesEntity==null?"/upload/2017-05-15/904e0fc3-a695-43cd-89f5-ebfa454b3699_s.png":
                    TextUtils.isEmpty(imagesEntity.getThumbnail())?"/upload/2017-05-15/904e0fc3-a695-43cd-89f5-ebfa454b3699_s.png"
            :(Constant.HTTPTITLE_Base+imagesEntity.getThumbnail())).error(R.mipmap.ic_launcher_round).into((ImageView) helper.getView(R.id.good_image));
    }
}
